<?php namespace Admin\Controller;
class BrandController extends CommonController{
	private $model;
	public function __init(){
		//调用CommonController里面的构造函数
		parent::__init();

	  	$this->model = new \Admin\Model\Brand;
	}
	//展示文章
	public function index(){
	 	$data = $this->model->get();
		View::with('data',$data);
	//载入模板
	    View::make();
	}
	
	//添加文章
	public function add(){
		if(IS_POST){
		   	if($this->model->store()) View::success('添加成功',U('index'));
			View::error($this->model->getError());
		}
	    View::make();
	}
	
	//删除
	public function del(){
	    $bid = Q('get.bid',0,'intval');
	    $this->model->where("bid=$bid")->delete();
		
		View::success('删除成功',U('index'));
	}
	
	 

	
	//编辑
	public function edit(){
		if(IS_POST){
		    if(!$this->model->edit()) View::error($this->model->getError());
			View::success('编辑成功',U('index'));
		}
		$bid = Q('get.bid',0,'intval');
	    $oldData = $this->model->where("bid=$bid")->find();

		View::with('oldData',$oldData);
		
	    View::make();
	}
	
	
	
	
	
	
	
	
	
	
	
}
	